<?php
	require '../biz/backend.php';

	class action extends backend
	{
		var $get_privilege_id = '88';

		function do_get()
		{
			$template = load( 'template', array( 'domain'=>'tpl.admin' ) );

			//栏目名称
			$cate = load( 'biz.cate' );
			$cata_data = $cate->all( array( 'size' => 99999 ) );
			$template->assign( 'cate_data', $cate->x_to_y( $cata_data['data'], 'id', 'cname' ));

			$html = load( 'biz.html' );
			$result = $html->all( $this->input );

			if ( $result['page'] > 1 )
			{
				$navigation = load( 'navigation' );
				$template->assign( 'bar', $navigation->compute( $result['total'], $result['size'] ) );
			}

			$template->assign( 'data', $result['data'] );
			$template->assign( 'current_url', config( 'current_url' ) );
			$template->assign( 'reference', isset( $this->input['reference'] ) ? urldecode( $this->input['reference'] ) : config( 'server.HTTP_REFERER' ) );
			echo $template->parse( 'list_html.php' );
		}

		/**
		 * 内容操作
		 * detail description
		 * @param string user
		 * @param integer id
		 * @return int|string|array|object|mixed
		 */
		function do_post()
		{
			$url = isset( $this->input['reference'] ) ? $this->input['reference'] : config( 'domain.admin' ) . 'list_tpl.php';
			unset( $this->input['reference'] );
			$op = isset( $this->input['op'] ) && preg_match( '/^\d+$/', $this->input['op'] ) ? $this->input['op'] : 0;

			if ( $op == 0 )
			{
				$this->prompt( '参数错误', array( array( 'url' => 'list_tpl.php', 'name' => '返回列表' ) ) );
			}

			$html = load( 'biz.html' );
			switch ( $this->input['op'] )
			{
				case 1:	//批量删除
					$this->input['on'] = 1;
					$result = $html->del( $this->input );
					break;

				case 2:	//批量取消删除
					$this->input['on'] = 1;
					$result = $html->del( $this->input );
					break;

				case 3:	//批量审核
					$this->input['on'] = 1;
					$result = $html->audit( $this->input );
					break;

				case 4:	//批量取消审核
					$this->input['on'] = 0;
					$result = $html->audit( $this->input );
					break;

				case 5:	//批量推荐到首页
					$this->input['on'] = 1;
					$this->input['target'] = 'home';
					$result = $html->promote( $this->input );
					break;

				case 6:	//批量取消推荐到首页
					$this->input['on'] = 0;
					$this->input['target'] = 'home';
					$result = $html->promote( $this->input );
					break;

				case 7:	//批量推荐到栏目首页
					$this->input['on'] = 1;
					$this->input['target'] = 'node';
					$result = $html->promote( $this->input );
					break;

				case 8:	//批量取消推荐到栏目首页
					$this->input['on'] = 0;
					$this->input['target'] = 'node';
					$result = $html->promote( $this->input );
					break;

				case 9:	//批量推荐到列表首页
					$this->input['on'] = 1;
					$this->input['target'] = 'list';
					$result = $html->promote( $this->input );
					break;

				case 10:	//批量取消推荐到列表首页
					$this->input['on'] = 0;
					$this->input['target'] = 'list';
					$result = $html->promote( $this->input );
					break;
			}

			if ( $result['success'] )
			{
				$this->prompt( '操作成功', array( array( 'url' => 'list_html.php', 'name' => '返回列表' ) ) );
			}
			else
			{
				$this->prompt( '操作失败', $this->transform( $result['message'], config( 'server.HTTP_REFERER' ) ) );
			}
		}

	}

	$action = new action();
	$action->run();
?>